//
//  LzwSingController.m
//  NewHalfsugar
//
//  Created by 刘志武 on 16/1/2.
//  Copyright © 2016年 刘志武. All rights reserved.
//

#import "LzwSingController.h"
#import "Block.h"
#import "LzwBaseView.h"
#import "LzwBaseImageView.h"
#import "UIImageView+WebCache.h"
#import "LzwSingWebViewVC.h"
#import "LzwbaseTableView.h"

@interface LzwSingController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) LzwbaseTableView *mySingTableView;
@property (nonatomic,retain) LzwBaseImageView *myIamge;

@end

@implementation LzwSingController

-(void)dealloc{
    
    [_myIamge dealloc];
    [_mySingTableView release];
    [super dealloc];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor orangeColor];
    
    self.navigationItem.title = @"每日一签";
    
    UIImage * returnPopPage = [UIImage imageNamed:@"return.png"];
    returnPopPage = [returnPopPage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:returnPopPage style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonAction:)];
    
    
    self.mySingTableView = [[LzwbaseTableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    self.mySingTableView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:self.mySingTableView];
    
    
    
    
    self.mySingTableView.dataSource = self;
    self.mySingTableView.delegate = self;
    
    [self.mySingTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    self.arraySing = [NSMutableArray array];
    
    NSString *string = @"http://open3.bantangapp.com/signin/monthList";
    
    NSDictionary *dict = @{@"app_installtime":@"1451365479.933367", @"app_versions":@"5.1.1", @"channel_name":@"appStore", @"client_id":@"bt_app_ios", @"client_secret":@"9c1e6634ce1c5098e056628cd66a17a5", @"device_token":@"c02c60075e7bab110fbdf27e15de3cb61e97360c4ea3545fd8a5936e46c28ccb", @"oauth_token":@"a41d3848f43102aa7759c27ba2c0fe8f", @"os_versions":@"9.1", @"screensize":@"640", @"track_device_info":@"iPhone5%2C3", @"track_deviceid":@"A80585E3-D6AD-4A53-BE1C-5963901C96E5", @"track_user_id":@"1746436", @"v":@"9"};
    
    
    [Block creatingDataTask:string parameters:dict Cookie:nil User_Agent:nil successAFNBlock:^(id resuposeObject) {
        
        NSMutableDictionary *diction = [resuposeObject objectForKey:@"data"];
        
        LzwSingHMdle *modleSd = [[LzwSingHMdle alloc]init];
        
        [modleSd setValuesForKeysWithDictionary:diction];
        
        [self.arraySing addObject:modleSd];
        
        [self.mySingTableView reloadData];
        
        NSURL *url = [NSURL URLWithString:modleSd.signin_bg_1];
        
        [self.myIamge sd_setImageWithURL:url placeholderImage:nil];
        
        
    }];
    
    
    
    //设置table的表头
    self.mySingTableView.tableHeaderView = [self creatHeader];
    //设置尾部
    self.mySingTableView.tableFooterView = [self creatFooter];
}

-(LzwBaseView *)creatHeader{
    
    LzwBaseView *headView = [[LzwBaseView alloc]initWithFrame:CGRectMake(0, 0, 375 * WIDTH, 350 * WIDTH)];
    headView.backgroundColor = [UIColor whiteColor];
    self.myIamge = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(0, 0, 375 * WIDTH, 350 * WIDTH)];
    self.myIamge.backgroundColor = [UIColor lightGrayColor];
    [headView addSubview:self.myIamge];

    return headView;
}

- (LzwBaseView *)creatFooter{
      LzwBaseView *FootView = [[LzwBaseView alloc]initWithFrame:CGRectMake(0, 405 * WIDTH, 375 * WIDTH, 150 * WIDTH)];
    
    LzwBaseImageView *myFootImage = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(0, 0, 375 * WIDTH, 150 * WIDTH)];
    myFootImage.image = [UIImage imageNamed:@"qiandao.png"];
    [FootView addSubview:myFootImage];
    
    
    return FootView;
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.detailTextLabel.text = @"去看看";
    cell.textLabel.text = @"我的签到";
    return cell;
    
    
}

//点击cell触发事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LzwSingWebViewVC *singWVC = [[LzwSingWebViewVC alloc]init];
    
    singWVC.str = @"http://m.bantangapp.com/users/badge/index?user_id=1746436";
    
    [self.navigationController pushViewController:singWVC animated:YES];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
    
}

- (void)leftButtonAction:(UIBarButtonItem *)bar{
    
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
